import { RouteRecordRaw } from "vue-router";
import { Menu } from "./Menu";
import router from "@/router/index";
import  { State } from "@/store";
import { useStore } from "vuex";

const admin_routes: Array<RouteRecordRaw> = [
    {
      name: "main",
      path: "/main",
      component: () => import("@/views/main/Main.vue"),
      children: [
        {
          path: "",
          component: () => import("@/views/main/admin/AdminHome.vue")
        },
        {
          path: "/admin/addTeacher",
          component: () => import("@/views/main/admin/AddTeacher.vue")
        },
        {
          path: "/admin/teachers",
          component: () => import("@/views/main/admin/ListTeachers.vue")
        },
        {
          path: "/admin/teachers/:tid",
          props: true,
          component: () => import("@/views/main/admin/TeacherDetail.vue")
        },
        {
          path:"/admin/addLaboratory",
          component: () => import("@/views/main/admin/AddLaboratory.vue")
        },
        {
          path:"/admin/laboratories",
          component: () => import("@/views/main/admin/ListLaboratories.vue")
        },
        {
          path:"/admin/laboratories/:lid",
          props: true,
          component: () => import("@/views/main/admin/LaboratoryDetail.vue")
        },
        {
          path:"/center",
          component: () => import("@/views/main/admin/AdminDetail.vue")
        }
      ]
    },
    {
        name: "nomatch",
      path: "/:pathMatch(.*)*",
      redirect: { name: "main" }
    }
  ];

  const teacher_routes: Array<RouteRecordRaw> = [
    {
      name: "main",
      path: "/main",
      component: () => import("@/views/main/Main.vue"),
      children: [
        {
          path: "",
          component: () => import("@/views/main/teacher/TeacherHome.vue")
        },
        {
          path: "/teacher/addCourse",
          component: () => import("@/views/main/teacher/AddCourse.vue")
        },
        {
          path: "/teacher/courses",
          component: () => import("@/views/main/teacher/ListCourses.vue")
        },
        {
          path: "/teacher/courses/:cid",
          props: true,
          component: () => import("@/views/main/teacher/CourseDetail.vue")
        },
        {
          path:"/teacher/addBooking",
          component: () => import("@/views/main/teacher/AddBooking.vue")
        },
        {
          path:"/teacher/bookings",
          component: () => import("@/views/main/teacher/ListBookings.vue")
        },
      
        {
          path:"/center",
          component: () => import("@/views/main/teacher/TeacherDetail.vue")
        }
      ]
    },
    {
        name: "nomatch",
      path: "/:pathMatch(.*)*",
      redirect: { name: "main" }
    }
  ];
  
  // ----------------
  const teacher_menuList:Menu[] = [
    {
      title: "课程管理模块",
      children: [
        {
          title: "新增课程",
          path: "/teacher/addCourse"
        },
        {
          title: "课程信息管理",
          path: "/teacher/courses"
        }
      ]
    },
    {
        title: "实验室预约模块",
        children: [
          {
            title: "新增预约",
            path: "/teacher/addBooking"
          },
          {
            title: "实验室预约管理",
            path: "/teacher/bookings"
          }
        ] 
    },
    {
      title: "个人管理模块",
      children: [
        {
          title: "个人中心",
          path: "/center"
        },
      ] 
  },
  ];

  const admin_menuList: Menu[] = [
    {
      title: "教师管理模块",
      children: [
        {
          title: "新增教师",
          path: "/admin/addTeacher"
        },
        {
          title: "教师信息管理",
          path: "/admin/teachers"
        }
      ]
    },
    {
        title: "实验室管理模块",
        children: [
          {
            title: "新增实验室",
            path: "/admin/addLaboratory"
          },
          {
            title: "实验室信息管理",
            path: "/admin/laboratories"
          }
        ] 
    },
    {
      title: "个人管理模块",
      children: [
        {
          title: "退出登录",
          path: ""
        },
      ] 
  },
  ];
  
  // --------------------
  
  export function setUserRole(role:string) {
    router.removeRoute("nomatch");
    if(role=="admin"){
        admin_routes.forEach(r => router.addRoute(r));
        return admin_menuList;
    }
    else{
        teacher_routes.forEach(r => router.addRoute(r));
        return teacher_menuList;
    }

    
  }